#include <head.h>
#include "./wrap.h"
#define SERVER_SOCKET "server.socket"
#define CLIENT_SOCKET "client.socket"
void fn(char *p);
int main(int argc ,char** argv)
{
    int r=0;
    int socket = Socket(AF_UNIX, SOCK_STREAM, 0);
    char buf[BUFSIZ];
    struct sockaddr_un  myaddr, server_addr;
    unlink(CLIENT_SOCKET);
    memset(&myaddr,0,sizeof(myaddr));
    myaddr.sun_family =AF_UNIX;
    strcpy(myaddr.sun_path,CLIENT_SOCKET);
    unlink(CLIENT_SOCKET);
    socklen_t len = offsetof(struct sockaddr_un, sun_path) + strlen(CLIENT_SOCKET);
    Bind(socket,(struct sockaddr*)&myaddr,len);
    memset(&server_addr,0,sizeof(server_addr));
    server_addr.sun_family =AF_UNIX;
    strcpy(server_addr.sun_path,SERVER_SOCKET);
    len = offsetof(struct sockaddr_un, sun_path) + strlen(SERVER_SOCKET);
    Connect(socket,(struct sockaddr*)&server_addr,len);

    while(1){
        CLEAR_ARRAY(buf);
        r= Read(STDIN_FILENO,buf,sizeof(buf));
        if(0 == strncmp("quit",buf,4)){
            break;
        }
        else{
            Write(socket,buf,r);
        }
        r= Read(socket,buf,sizeof(buf));
        Write(STDOUT_FILENO,buf,r);
    }
    Close(socket);
    return 0;
}
void fn(char *p)
{
    if(!p){
        return;
    }
    while (*p)
    {
        *p =toupper(*p);
        p++;
    }
    
}
